Public Class FormBackupDatabase

    Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
        Try



            If BackupDatabase.BackUpDatabase("HR_DB", lblFileAndPath.Text, "Format") = True Then
                MessageBox.Show("BACKUP DATABASE successfully", "Human Resource Management System", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
                Me.Close()
            Else
                MessageBox.Show("BACKUP DATABASE is terminating abnormally.", "Dental Clinic", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
                txtFileName.Focus()
            End If



        Catch ex As Exception
        End Try
    End Sub

 

    Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
        With BrowsePath
            .Description = "Select Backup Location"
            .RootFolder = Environment.SpecialFolder.MyComputer
            '.SelectedPath = "C:\"
            .ShowNewFolderButton = True
            If .ShowDialog = Windows.Forms.DialogResult.Cancel Then
                Exit Sub
            End If

            Dim strPath As String = .SelectedPath.Trim
            Me.txtLocation.Text = strPath

            Try

                If strPath.Trim.Substring(strPath.Length - 1, 1) = "\" Then
                    strPath = strPath.Substring(0, strPath.Length - 1)
                End If

                If Me.txtFileName.Text.Trim = String.Empty Then
                    lblFileAndPath.Text = txtLocation.Text & "\"
                Else
                    lblFileAndPath.Text = txtLocation.Text & "\" & Me.txtFileName.Text.Trim & ".Bak"
                End If
                lblSelectedfile.Visible = True

            Catch ex As Exception
                'MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            End Try
        End With
    End Sub

    Private Sub txtLocation_TextChanged(sender As Object, e As EventArgs) Handles txtLocation.TextChanged
        Try
            If txtFileName.Text.Trim <> String.Empty And txtLocation.Text.Trim <> String.Empty Then
                lblFileAndPath.Text = txtLocation.Text & "\" & txtFileName.Text & ".Bak"
                btnOK.Enabled = True
            Else
                lblFileAndPath.Text = txtLocation.Text
                btnOK.Enabled = False

            End If

        Catch ex As Exception

        End Try
    End Sub

    Private Sub txtFileName_TextChanged(sender As Object, e As EventArgs) Handles txtFileName.TextChanged
        Try
            If txtFileName.Text.Trim <> String.Empty And txtLocation.Text.Trim <> String.Empty Then
                lblFileAndPath.Text = txtLocation.Text & "\" & txtFileName.Text & ".Bak"
                btnOK.Enabled = True
            Else
                lblFileAndPath.Text = txtLocation.Text
                btnOK.Enabled = False

            End If

        Catch ex As Exception

        End Try
    End Sub

  
    
     
    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
        Try
            Me.Close()

        Catch ex As Exception

        End Try
    End Sub

 
    
End Class